// 存储本地用户id
document.body.addEventListener('connected', function (evt) {
    // console.log('localuserId', localuserId);
    localuserId = evt.detail.clientId;
    console.error('localuserId', localuserId);
    setAvatarId();
});

// 新用户进入为其设置当前对战初始值
document.body.addEventListener('clientConnected', function (evt) {
    console.error('remote clientConnected event. clientId =', evt.detail.clientId);
    const info_left = document.querySelector('#id_left');
    const info_right = document.querySelector('#id_right');
    const info_leftValue = info_left.getAttribute('text').value;
    const info_rightValue = info_right.getAttribute('text').value;
    // 如果是左边对战者，则将记分板信息同步给新用户，减少同步次数。这里就只会同步1次
    if (info_leftValue === localuserId) {
        // 原始分数
        const score_left = document.querySelector('#score_left');
        let originalScore_left = score_left.getAttribute('text').value;
        // originalScore_left = Number(originalScore_left);
        const score_right = document.querySelector('#score_right');
        let originalScore_right = score_right.getAttribute('text').value;
        // originalScore_right = Number(originalScore_right);

        const clientId = evt.detail.clientId;
        const data = {
            info_leftValue: info_leftValue,
            info_rightValue: info_rightValue,
            originalScore_left: originalScore_left,
            originalScore_right: originalScore_right,
            shootGameLock: shootGameLock
        }

        NAF.connection.sendData(clientId, dataType_scoreBoardInitialize, data);
    }

});

// 首屏提示
const block = document.querySelector('#blocker');
const sceneLoadCounter = document.querySelector('.scene-load-counter');
dealSceneLoad(block,sceneLoadCounter,0,sceneWaitTime);


